<?php
/**
 *
 */
namespace app\common\query;
use app\common\model\OrderDetails as OrderDetailsModel;
use app\common\cache\CacheData;
class OrderDetails
{
    protected $resultSetType = 'collection';
    /**
     * 查询订单商品
     * @return [type] [description]
     */
    public static function getDatas($where=[],$field=''){
        $model = new OrderDetailsModel;
        $data = $model->where($where)->field($field)->select();
        foreach($data as &$row):
            $row = self::setRemark($row);
        endforeach;
        return $data;
    }

    /**
     * 处理字段数据
     * @param [type] $row [description]
     */
    public static function setRemark($row){
        if(isset($row['gid'])){
             $data = \app\common\query\MallGoods::getGoodsDetail($row['gid'],'title,coin_id,cate_id,price,photo');
             $row['title']= $data['title'];
             $row['coin_name']= $data['coin_name'];
             $row['coin_id']= $data['coin_id'];
             $row['cate_name']= $data['cate_name'];
             $row['cate_id']= $data['cate_id'];
             $row['photo']= $data['photo'];
             $row['title']= $data['title'];
        }
        return $row;
    }

    public static function add($data=[]){
        $model = new OrderDetailsModel;
        return $model->save($data);
    }

    public static function del($data=[]){
        $model = new OrderDetailsModel;
        $datas = $model->where($data)->delete();
    }
}